.TH std::basic_string::starts_with 3 "2024.06.10" "http://cppreference.com" "C++ Standard Libary"
.SH NAME
std::basic_string::starts_with \- std::basic_string::starts_with

.SH Synopsis
   constexpr bool
       starts_with( std::basic_string_view<CharT,Traits> sv ) const   \fB(1)\fP \fI(since C++20)\fP
   noexcept;
   constexpr bool                                                     \fB(2)\fP \fI(since C++20)\fP
       starts_with( CharT ch ) const noexcept;
   constexpr bool                                                     \fB(3)\fP \fI(since C++20)\fP
       starts_with( const CharT* s ) const;

   Checks if the string begins with the given prefix. The prefix may be one of the
   following:

   1) A string view sv (which may be a result of implicit conversion from another
   std::basic_string).
   2) A single character ch.
   3) A null-terminated character string s.

   All three overloads effectively return std::basic_string_view<CharT, Traits>(data(),
   size()).starts_with(x), where x is the parameter.

.SH Parameters

   sv - a string view which may be a result of implicit conversion from another
        std::basic_string
   ch - a single character
   s  - a null-terminated character string

.SH Return value

   true if the string begins with the provided prefix, false otherwise.

.SH Notes

       Feature-test macro      Value    Std                    Feature
   __cpp_lib_starts_ends_with 201711L (C++20) String prefix and suffix checking:
                                              starts_with() and ends_with()

.SH Example


// Run this code

 #include <cassert>
 #include <string>
 #include <string_view>

 int main()
 {
     using namespace std::literals;

     const auto str = "Hello, C++20!"s;

     assert
     (""
         && str.starts_with("He"sv)  // (1)
         && !str.starts_with("he"sv) // (1)
         && str.starts_with("He"s)   // (1) implicit conversion string to string_view
         && !str.starts_with("he"s)  // (1) implicit conversion string to string_view
         && str.starts_with('H')     // (2)
         && !str.starts_with('h')    // (2)
         && str.starts_with("He")    // (3)
         && !str.starts_with("he")   // (3)
     );
 }

.SH See also

   ends_with   checks if the string ends with the given suffix
   (C++20)     \fI(public member function)\fP
   starts_with checks if the string view starts with the given prefix
   (C++20)     \fI(public member function of std::basic_string_view<CharT,Traits>)\fP
   ends_with   checks if the string view ends with the given suffix
   (C++20)     \fI(public member function of std::basic_string_view<CharT,Traits>)\fP
   contains    checks if the string contains the given substring or character
   (C++23)     \fI(public member function)\fP
   contains    checks if the string view contains the given substring or character
   (C++23)     \fI(public member function of std::basic_string_view<CharT,Traits>)\fP
   compare     compares two strings
               \fI(public member function)\fP
   substr      returns a substring
               \fI(public member function)\fP
